<?php

namespace Zilla\FrontBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Zilla\FrontBundle\Entity\ProWinker;


class StoreController extends Controller
{
    /**
     *
     * @return RedirectResponse
     */
    public function indexAction()
    {
        $stores=$this->get('doctrine')->getRepository('ZillaFrontBundle:Store')->findAll();
        return $this->render('ZillaFrontBundle:Store:index.html.twig', array('stores' => $stores));
    }
    
    /**
     *
     * @param string $alias
     * @return Response 
     */
    public function winkStoreAction($alias)
    {
        $request = $this->get('request');
        if ($request->isXMLHTTPRequest()) {
            $proWinker = $this->get('security.context')->getToken()->getUser();
            $store = $this->get('doctrine')->getRepository('ZillaFrontBundle:Store')->findOneBy(array('alias' => $alias));
            $this->get('session')->get('stores');
            $store->addProFollower($proWinker);
            $this->get('doctrine.orm.entity_manager')->persist($store);
            $this->get('doctrine.orm.entity_manager')->flush();
            return new Response();
        }
    }
}
